package A3GCConcreteTestCase;

import A3JGroups.A3JGMessage;
import A3JGroups.JGFollowerRole;

public class ClientNode extends JGFollowerRole 
{

	public ClientNode(int resourceCost, String groupName) 
	{
		super(resourceCost, groupName);
	}

	@Override
	public void run() 
	{
		boolean first = true;
		int count = 0;
		int max = 5000;		
		
		while ( this.active )
		{
			try
			{
				count += 500;
				Thread.sleep(500);
			}
			catch (Exception e)
			{
				
			}
			
			if ( first )
			{
				A3JGMessage mex;
				
				mex = new A3JGMessage();
				mex.setContent("Special#3#"+getChan().getAddress());
				
				System.out.println("Client is sending a message to the supervisor" );
				sendMessageToSupervisor(mex);
				
				first = false;
			}
			
			if ( count > max )
			{
				count = 0;
				
				A3JGMessage mex;
				
				mex = new A3JGMessage();
				mex.setContent("Special#15#"+getChan().getAddress());
				
				System.out.println("Client is sending another message to the supervisor" );
				sendMessageToSupervisor(mex);
			}
		}
	}

	@Override
	public void messageFromSupervisor(A3JGMessage msg) 
	{
		System.out.println("Client Node has received a response from the supervisor: <" + msg.getContent().toString() + ">");
	}

}
